#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import sys
from loguru import logger
from conf.settings import *
#from conf import settings

'''
Preparation:
    1. pip3 install loguru

'''
#LOG_FILE='log/runtime_{time}.log'
#LOGERR_FILE='log/error_{time}.log'

#LOG_FILE='log/runtime.log'
#LOGERR_FILE='log/error.log'

class tlog(object):
    def __init__(self):
        pass

    def define(self):
        BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        log_file_path = os.path.join(BASE_DIR, LOG_FILE)
        err_log_file_path = os.path.join(BASE_DIR, LOGERR_FILE)
        logger.add(sys.stderr, format="{time} {level} {message}", filter="my_module", level="INFO")
        #logger.add(sys.stderr, format="{time} {level} {message}", filter="my_module", level="ERROR")
        # logger.add(s)
        logger.add(log_file_path, rotation="500 MB", encoding='utf-8')  # Automatically rotate too big file
        logger.add(err_log_file_path, rotation="500 MB", encoding='utf-8',level='ERROR')  # Automatically rotate too big file
        #logger.debug("That's it, beautiful and simple logging!")
        #logger.debug("中文日志可以不")
        #logger.error("严重错误")
        return logger